/**
 * JavaScript  beautyDate
 * 
 * @author mixed <mailto:i . nevalose (at) gmail . com>
 * @license GNU
 * @blog http://mixed.tistory.com/
 * 
 * @param {Date} date
 * @param {Object} customOption
 * 
 * @return {String} beautyDate
 */
function beautyDate(date,customOption){
	if(arguments.length<1||date.constructor != Date){
		return false;
	}
	var options = {
		format		:"{yyyy}/{mm}/{0d} {0h}:{0i}",
		monthFormat :["01","02","03","04","05","06","07","08","09","10","11","12"],
		weekFormat	:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],
		ampmFormat	:["am","pm"]
	}
	customOption = customOption||{};
	for(var i in customOption){
		options[i] = customOption[i];
	}
	options["rowData"] = [date.getFullYear()+"",
						  date.getMonth(),
						  date.getDate(),
						  date.getDay(),
						  date.getHours()<12?0:1,
						  date.getHours(),
						  date.getMinutes(),
						  date.getSeconds()];
	return options.format.replace(/\{([^{}]*)\}/g,function(){
		var coptions = options;
		var type = arguments[0];

		function addZero(num){
			return (num>=10)?num:"0"+num;
		}
		function twelveNotation(num){
			return (num>12)?num-12:num;
		}
		var rowData 	= coptions.rowData;
		var monthFormat = coptions.monthFormat;
		var weekFormat  = coptions.weekFormat;
		var ampmFormat  = coptions.ampmFormat;
		
		return type=="{yyyy}"&&rowData[0]||
			   type=="{yy}"&&rowData[0].slice(2,4)||
			   type=="{mm}"&&monthFormat[rowData[1]]||
			   type=="{dd}"&&rowData[2]||
			   type=="{0d}"&&addZero(rowData[2])||
			   type=="{ww}"&&weekFormat[rowData[3]-1]||
			   type=="{ap}"&&ampmFormat[rowData[4]]||
			   type=="{hh}"&&twelveNotation(rowData[5])||
			   type=="{HH}"&&rowData[5]||
			   type=="{0h}"&&addZero(twelveNotation(rowData[5]))||
			   type=="{0H}"&&addZero(rowData[5])||
			   type=="{ii}"&&addZero(rowData[6])||
			   type=="{0i}"&&addZero(rowData[6])||
			   type=="{ss}"&&rowData[7]||
			   type=="{0s}"&&addZero(rowData[7])||"Undefined-Format";

	});
}
		